package chances.webui.model;

import java.util.ArrayList;
import java.util.List;

public class TreeNode<T> {
	private String title;
	private String name;
	private String icon;
	private String path;
	private String action;
	private String link;
	private String id;
	private String parentId;
	private String status;


	private boolean leaf;
	private T entry;
	private TreeNode<T> parent;

	private List<TreeNode<T>> children = new ArrayList<TreeNode<T>>();

	public String getTitle() {
		return title;
	}

	public String getName() {
		return name;
	}

	public String getIcon() {
		return icon;
	}

	public String getAction() {
		return action;
	}

	public String getLink() {
		return link;
	}
	
	

	public void setTitle(String title) {
		this.title = title;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public void setAction(String action) {
		this.action = action;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public T getEntry() {
		return entry;
	}

	public List<TreeNode<T>> getChildren() {
		return children;
	}

	public void setEntry(T entry) {
		this.entry = entry;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public void addChild(TreeNode<T> s) {
		this.children.add(s);
		s.setParent(this);
	}

	public void walk(TreeWalker<T> treeWalker) {
		treeWalker.walk(this);
		this.children.forEach(s -> treeWalker.walk(s));
	}

	public TreeNode<T> getParent() {
		return parent;
	}

	public void setParent(TreeNode<T> parent) {
		this.parent = parent;
	}

	
	public boolean hasChild(){
		return !this.children.isEmpty();
	}
	public String getPathName() {
		if (this.getParent() != null) {
			return this.getParent().getPathName() + "/" + this.getTitle();
		} else {
			return this.getTitle();
		}
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}
	
	public boolean isLeaf() {
		return leaf;
	}

	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}
}
